import java.util.Scanner;

public class Test4 {
    // dd爱科学
    // https://ac.nowcoder.com/acm/problem/221822
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char[] cc = in.next().toCharArray();
        char[] dp = new char[1000001];
        int index = 0;
        for (char c : cc) {
            if (index == 0 || c >= dp[index]) {
                dp[++index] = c;
            } else {
                int left = 0;
                int right = index;
                while (left < right) {
                    int mid = left + (right - left) / 2;
                    if (dp[mid] > c) {
                        right = mid;
                    } else {
                        left = mid + 1;
                    }
                }
                dp[left] = c;
            }
        }
        System.out.println(n-index);
    }
}
